package edu.thu.studio.ormdesigner.outline.action;

import org.eclipse.gef.ui.parts.TreeViewer;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.PlatformUI;

import edu.thu.studio.ormdesigner.model.diagram.Diagram;
import edu.thu.studio.ormdesigner.outline.command.UpdateDiagramCommand;
import edu.thu.studio.ormdesigner.outline.dialog.DiagramDialog;
import edu.thu.studio.ormdesigner.util.Properties;

public class UpdateDiagramAction extends AbstractOutlineAction {
    
    public static final String ID = UpdateDiagramAction.class.getName();
    
    public UpdateDiagramAction(TreeViewer treeViewer) {
        super(ID, Properties.outline_menu_updatediagram, treeViewer);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public void execute(Event event) {
        Diagram diagram = (Diagram) this.getSelectedModel();
        
        DiagramDialog dialog = new DiagramDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            diagram);
        
        if (dialog.open() == IDialogConstants.OK_ID) {
            UpdateDiagramCommand command = new UpdateDiagramCommand(this.getORMModel(), diagram, dialog.getResult());
            this.execute(command);
        }
    }
}
